var cdcDataId = window.parent.CdcData.seItem.id;
var initColumn = function () {
    return [
        { field: 'selectItem', checkbox: true },
        { title: '代码', field: 'code', align: 'center', valign: 'middle', sortable: true },
        { title: '描述', field: 'description', align: 'center', valign: 'middle', sortable: true }
    ];
};


//获取数据
var dataTable = [];
var selectedTable = function () {
    var ajax = new $ax(Sys.backendPath + "/cdc/datatable/query", function (data) {
        dataTable = data;
    }, function (data) {
        Sys.error("数据获取失败!");
    });
    ajax.set("sysDataId", cdcDataId);
    ajax.setAsync(true);
    ajax.start();
}
selectedTable();

var LoadSuccess = function (data) {
    if (dataTable.length == 0) return;
    for (var i = 0; i < data.length; i++) {
        var e = data[i];
        for (let j = 0; j < dataTable.length; j++) {
            var d = dataTable[j];
            if (e.id == d.sysDictionaryId) {
                $("#CdcDataTableList").bootstrapTable('check', i);
                dataTable.splice(j,1);
            }
        }
    }
}

var defaultColunms = initColumn();
var DataTable = new BSTable("CdcDataTableList", Sys.backendPath + "/cdc/dictionary/query/CDC/CDCCTDataTable", defaultColunms);
DataTable.setPaginationType("client");
DataTable.setPageSize(20);
DataTable.setShowRefresh(false);
DataTable.setShowColumns(false);
DataTable.setShowToggle(false);
DataTable.setShowExport(false);
DataTable.setOnLoadSuccess(LoadSuccess);
DataTable = DataTable.init();

var saveTable = function () {
    var selected = $('#CdcDataTableList').bootstrapTable('getSelections');
    var ids = "";
    for (var index = 0; index < selected.length; index++) {
        var element = selected[index];
        ids = ids + "," + element.id;
    }
    var tableIds = ids.substr(1);
    var ajax = new $ax(Sys.backendPath + "/cdc/cdcdata/savecttable", function (data) {
        Sys.success("关联成功!");
    }, function (data) {
        Sys.error("关联失败!" + data.responseJSON.message + "!");
    });
    ajax.set("tableIds", tableIds);
    ajax.set("cdcDataId", cdcDataId);
    ajax.start();
}